package com.li.algorithm.leetcode.hot100;


import java.util.Objects;

public class Test22 {

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode a = headA;
        ListNode b = headB;

        while (a != null && b != null) {
            if (Objects.equals(a, b)) {
                return a;
            }
            if (a.next == null && b.next != null) {
                a = headB;
                b = b.next;
                continue;
            }
            if (b.next == null && a.next != null) {
                b = headA;
                a = a.next;
                continue;
            }
            a = a.next;
            b = b.next;
        }
        return null;
    }
}
